<%@ page contentType="text/html;charset=utf-8" 
    import="java.util.*,com.zh.User,com.zh.UserBean,com.zh.Util,org.springframework.web.context.*,com.zh.House,org.springframework.web.context.support.*"
%>    
<%
    	List<User> userlist = (List<User>)request.getAttribute("userlist");
    %>
<html>
  <head>
    <title>业户信息管理</title>
	<link rel=stylesheet href="css/general.css" type="text/css">
    <script language="JavaScript" src="script/com.js"></script>
    <script language="JavaScript">
      function check(){
      	var key = document.all.keywords.value.trim();
      	if(key==""){
			alert("关键字为空,请重新输入!!!");
			return;
      	}
      	document.all.ss.submit();
      }
      function checkPage(temp){
      	var page = document.all.page.value.trim();
  		var reg = /^[1-9][0-9]*$/;
		if((reg.test(page.trim()))&&(page<=temp)){
			document.all.mf.submit();
		}
		else{
			alert("输入不合法,请重新输入!!!");
			return;
		}
      }
    </script>
    <style>
	       .mima {
	       width:100%;
	       height:40px;
	       background-color:#ADD8E6;
	       }
	       .zi {
	       font-size:20px;
	       position:relative;
	       left:45%;
	       margin-left:-30px;
	       line-height:40px;
	       }
	</style>
  </head>
  <body >
  	<jsp:useBean id="userBean" class="com.zh.UserBean" scope="session"/>
	<div class="mima"><font class="zi">业户信息管理</font></div>
	<form action="SuperServlet" method="post" id="ss">
	 <div>
		<table height="20px" >
		  <tr>
		    <td>
		      <input name="keywords" id="keywords" value="请输入要搜索的内容" size="28"	onfocus="document.all.keywords.value=''"/>		    
		    </td>
		    <td >
		    <input type="button" value="搜索" id="bt"  style="cursor:hand" onclick="JavaScript:check()"/>
		    </td>
		    <td align="center">
 		      <input type="radio" name="radio" value="userId" checked="true"><font size="2" color="black">按业主ID</font>
	     	</td>
	     	<td >
	     	  <input type="radio" name="radio" value="username"><font size="2" color="black">按姓名</font>
		    </td>
	    	<td>
	    	  <a href="adduser.jsp" target="rightFrame"><font size="2" color="black">添加业主</font></a>
	    	</td> 
	    	<td>
	         <input type="hidden" name="action" value="looksearch" />
	        <input type="hidden" name="type" value="User"/>
	       </td>	 
		  </tr>
		</table>
	  </div>
	</form>
	<% 
		if(userlist.isEmpty()){
			out.println("<br/><br/><br/><center><h2>没有搜索到你要的商品!!!</h2></center>");
		}
		else{
		
	 %>
	<table  width="98%" border="0" cellspacing="1" style="background-color:#000000" align="center" class="update">
	  <tr bgcolor="#ADD8E6" align="center">	 
	    <th>业主ID</th>
	    <th>业主姓名</th>
	  	<th>性别</th>
	  	<th>职业</th>
	  	<th>电话</th>
	  	<th>入住时间</th>
	  	<th>入住人口</th>
	  	<th>房屋地址</th>
	  	<th>查看/修改</th>
	  	<th>删除</th>
	  </tr>
	<%
		//获取WebApplicationContext
		WebApplicationContext w=
		   WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
		Util util = (Util)w.getBean("Util");
		int i = 0;
		for(User u:userlist){
		String userId = u.getUserId();
		String houseId=u.getHouseId();
		House h=(House)util.getObject("house",houseId);
		String username=u.getUsername();
		String sex=u.getUsersex();
		String profe=u.getUserprofession();
		String phonenumber=u.getPhonenumber();
		Date ltime=u.getLivetime();
		int lcount=u.getLivecount();
	
		if(i%2==0){
			i++;
			out.println("<tr bgcolor='white' align='center'>");
		}
		else{
			i++;
			out.println("<tr bgcolor='#ADD8E6' align='center'>");
			
		}
	 %>
	   
	    <td><%= userId %></td>
	    <td><%= username %></td>
	    <td><%= sex %></td>
	    <td><%= profe %></td>
	    <td><%= phonenumber %></td>
	    <td><%= ltime %></td>
	    <td><%= lcount %></td>
	    <td><%= h.getHouseaddress() %></td>
	    <td ><a href="SuperServlet?action=seekuser&userId=<%= u.getUserId() %>" target="rightFrame"><img border="0" src="img/mod.gif"/>查看/修改</a></td>
	    <td ><a href="JavaScript:del('SuperServlet?action=deluser&uId=<%= u.getUserId()%>')" target="rightFrame"><img border="0" src="img/del.gif"/>删除</a></td>
	  </tr>
	<%
		}
	 %>
	</table>	
	<table width="98%">
	<form method="post" id="mf" action="SuperServlet">
	  <tr>
	    <td align="left">
	      <font size="2">共<%= userBean.getCountpage() %>页&nbsp;&nbsp;当前页:<%= userBean.getCurrentpage() %></font>
	    </td>
	    <td align="right">
	      <% 
	      	if(userBean.getCurrentpage()>1){
	       %>
	      <a href="SuperServlet?action=changePage&pagename=/userManage.jsp&page=<%= userBean.getCurrentpage()-1 %>" target="rightFrame"><img src="img/prev.gif" border="0"/></a>
	      <% 
	      	}
	      	if(userBean.getCurrentpage()<userBean.getCountpage()){
	       %>	       
	      <a href="SuperServlet?action=changePage&pagename=/userManage.jsp&page=<%= userBean.getCurrentpage()+1 %>" target="rightFrame"><img src="img/next.gif" border="0"/></a>
	      <% 
	      	}
	      	else{
	      		out.println("<img src='img/next.gif' style='visibility:hidden'/>");
	      	}
	       %>
	      <font size="2">第<input name="page" id="page" size="2" value="<%= userBean.getCurrentpage() %>" onfocus="document.all.page.value=''"/>页</font>
	      <input type="hidden" name="action" value="changePage" />
	      <input type="hidden" name="pagename" value="/userManage.jsp"/>	    
	    </td>
	    <td width="10">
	      <input type="button" value="跳转" style="cursor:hand" onclick="JavaScript:checkPage(<%= userBean.getCountpage() %>)">
	    </td>
	  </tr>	
	</form>
	</table>
	<% 
		}
	 %>
  </body>
</html>